/** @namespace app.spider.PlatformType */
module.exports = app => {
  const {INTEGER} = app.Sequelize;
  const PlatformType = app.spider.define('platform_type', {
    id: {type: INTEGER, autoIncrement: true, primaryKey: true},
    platform_id: {type: INTEGER, unique: 'p_t_id'},
    type_id: {type: INTEGER, unique: 'p_t_id'},
  }, {
    timestamps: false,
    tableName: 'spider_platform_type',
  });

  PlatformType.associate = () => {

    app.spider.Type.belongsToMany(app.spider.Platform,
        {
          through: app.spider.PlatformType,
          as: 'platform',
          foreignKey: 'type_id',
        });
    app.spider.Platform.belongsToMany(app.spider.Type,
        {
          through: app.spider.PlatformType,
          as: 'type',
          foreignKey: 'platform_id',
        });

    app.spider.PlatformType.belongsTo(app.spider.Platform);
    app.spider.PlatformType.belongsTo(app.spider.Type);
  };

  return PlatformType;
};